//
//  ViewController.m
//  rutime获取状态栏
//
//  Created by webplus on 17/8/30.
//  Copyright © 2017年 sanyi. All rights reserved.
//

#import "ViewController.h"
#import <objc/message.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    // 状态栏是由当前app控制的，首先获取当前app
    UIApplication *app = [UIApplication sharedApplication];
    //获取状态栏的所有子视图
    NSArray *children = [[[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"foregroundView"] subviews];
    
    int type = 0;
    //遍历子视图
    for (id child in children) {
        if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {
            type = [[child valueForKeyPath:@"dataNetworkType"] intValue];
        }
    }
    //打印出的type数字对应的网络状态依次是：0 - 无网络; 1 - 2G; 2 - 3G; 3 - 4G; 5 - WIFI
    NSLog(@"----%d", type);
    
    
}

- (void)getIvarListList{
    UIApplication *app = [UIApplication sharedApplication];
    unsigned int outCount = 0;
    Ivar *ivars = class_copyIvarList(app.class, &outCount);
    for(int i = 0; i < outCount; i++){
        Ivar ivar = ivars[i];
        NSLog(@"%s",ivar_getName(ivar));
    }

}

- (void)getStatusBarDataNetworkItemViewList{
    // 状态栏是由当前app控制的，首先获取当前app
    UIApplication *app = [UIApplication sharedApplication];
    //获取状态栏的所有子视图
    NSArray *children = [[[app valueForKeyPath:@"statusBar"] valueForKeyPath:@"foregroundView"] subviews];
    //遍历子视图
    for (id child in children) {
        if ([child isKindOfClass:NSClassFromString(@"UIStatusBarDataNetworkItemView")]) {
            unsigned int outCount = 0;
            Ivar *ivars = class_copyIvarList([child class], &outCount);
            for(int i = 0; i < outCount; i++){
                Ivar ivar = ivars[i];
                NSLog(@"%s",ivar_getName(ivar));
            }
        }
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
